<template>
  <van-list
    v-model:loading="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
  >
    <ul class="goods-list">
      <li
        v-for="item in goodsList"
        :key="item.proid"
        @click="onClickDetail(item.proid)"
      >
        <p class="goods-list-img"><img :src="item.img1" /></p>
        <p>{{ item.proname }}</p>
        <p class="money">￥：{{ item.originprice }}</p>
      </li>
    </ul>
  </van-list>
</template>

<script>
import { getGoodsPageList } from "@/api/home";
export default {
  name: "GoodsList",
  data() {
    return {
      goodsList: [],
      loading: false,
      finished: false,
      count: 1,
    };
  },
  methods: {
    onLoad() {
      this.getGoodsList();
    },
    // 获取分页列表
    async getGoodsList() {
      this.loading = true;
      let res = await getGoodsPageList({
        count: this.count++,
        limitNum: 20,
      });

      if (res.data.code == 200) {
        console.log(res);

        if (res.data.data.length > 0) {
          this.goodsList.push(...res.data.data);
        } else {
          this.finished = true;
        }
      }
      this.loading = false;
    },
    onClickDetail(id) {
      this.$router.push('/Detail/'+ id);
    },
  },
  created() {
    this.getGoodsList()
  }
};
</script>

<style scoped>
.goods-list {
  width: 98%;
  column-count: 2;
  /* margin: 0 auto; */
}
.goods-list li {
  width: 100%;
  height: 100%;
  background-color: #eee;
  font-size: 14px;
  box-sizing: border-box;
  padding: 5px;
  margin: 5px;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* border: 1px solid rgb(19, 17, 17); */

  justify-content: space-between;
}

.goods-list li .money {
  width: 1rem;
  height: 0.3rem;
  background-color: red;
  color: white;
  text-align: center;
  line-height: 30px;
  font-size: 0.14rem;
  margin: 10px 0px;
  border-radius: 5px;
}

.goods-list-img img {
  width: 100%;
  height: 100%;
  border-radius: 0.1rem;
}
</style>
